package com.sgb.kjwl.viewmodel.home;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.CentralizedActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class CentralizedModel extends BaseViewModel {
    private HomeRepertory repertory;
    private CentralizedActivity activity;


    public CentralizedModel(CentralizedActivity activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getFirstCategory(String type) {
        DialogHelper.showProgressDialog(activity, null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);

        if (!type.equals("3")) {
            APIManager.getInstance().getCentralizedMiningAPI().getFirstCategory(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
                @Override
                public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                    DialogHelper.dismissProgressDialog();
                    if (response.body() == null || response.body().getState() == null) {
                        return;
                    }

                    if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                        activity.showFirstCategory(response.body().getData());
                    }
                }

                @Override
                public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                    DialogHelper.dismissProgressDialog();

                }
            });
        } else {
//            企业专项类别请求
        /*    APIManager.getInstance().getCentralizedMiningAPI().getTypeList(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
                @Override
                public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                    DialogHelper.dismissProgressDialog();
                    if (response.body() == null || response.body().getState() == null) {
                        return;
                    }

                    if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                        List<PickSelectEntity> data = response.body().getData();
                        PickSelectEntity entity = new PickSelectEntity();
                        entity.setNo("0");
                        entity.setProjectscale("全部");
                        data.add(0, entity);
                        activity.showFirstCategory(data);
                    }
                }

                @Override
                public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                    DialogHelper.dismissProgressDialog();
                }
            });*/
        }
    }
}
